using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Terra.Core.Common.ApiResponse;
using Terra.Service.Identity.DTOs;
using Terra.Core.Common.Enums.Identity;

namespace Terra.Service.Identity.Interfaces;

/// <summary>
/// 认证服务接口
/// </summary>
public interface IAuthService
{
    /// <summary>
    /// 用户注册
    /// </summary>
    /// <param name="request">注册请求</param>
    /// <returns>注册响应</returns>
    Task<ApiResponse<RegisterResponseDto>> RegisterAsync(RegisterRequestDto request);

    /// <summary>
    /// 用户登录
    /// </summary>
    /// <param name="request">登录请求</param>
    /// <returns>登录响应</returns>
    Task<ApiResponse<LoginResponseDto>> LoginAsync(LoginRequestDto request);

    /// <summary>
    /// 用户登出
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>操作结果</returns>
    Task<ApiResponse> LogoutAsync(Guid userId);

    /// <summary>
    /// 获取用户信息
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>用户信息</returns>
    Task<ApiResponse<UserDto>> GetUserInfoAsync(Guid userId);

    /// <summary>
    /// 刷新访问令牌
    /// </summary>
    /// <param name="request">刷新令牌请求</param>
    /// <returns>新的访问令牌</returns>
    Task<ApiResponse<TokenResponseDto>> RefreshTokenAsync(RefreshTokenRequestDto request);

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="request">修改密码请求</param>
    /// <returns>操作结果</returns>
    Task<ApiResponse<object>> ChangePasswordAsync(Guid userId, ChangePasswordRequestDto request);

    /// <summary>
    /// 验证用户凭据
    /// </summary>
    /// <param name="username">用户名/手机号/邮箱</param>
    /// <param name="password">密码</param>
    /// <returns>验证结果</returns>
    Task<(bool success, string message, ClaimsPrincipal principal)> ValidateCredentialsAsync(string username, string password);

    /// <summary>
    /// 生成访问令牌
    /// </summary>
    /// <param name="principal">身份信息</param>
    /// <returns>访问令牌</returns>
    Task<(string accessToken, string refreshToken)> GenerateTokensAsync(ClaimsPrincipal principal);

    /// <summary>
    /// 撤销刷新令牌
    /// </summary>
    /// <param name="refreshToken">刷新令牌</param>
    Task RevokeRefreshTokenAsync(string refreshToken);

    #region 密码重置
    /// <summary>
    /// 发起密码重置
    /// </summary>
    /// <param name="account">账号(邮箱/手机)</param>
    /// <param name="resetType">重置方式(邮件/短信)</param>
    /// <param name="operatorId">操作人ID(管理员重置时需要)</param>
    /// <returns>操作结果</returns>
    Task<ApiResponse> InitiatePasswordResetAsync(string account, ResetType resetType, string operatorId = null);

    /// <summary>
    /// 验证并重置密码
    /// </summary>
    /// <param name="token">验证token/验证码</param>
    /// <param name="newPassword">新密码</param>
    /// <param name="resetType">重置方式</param>
    /// <returns>操作结果</returns>
    Task<ApiResponse> ValidateAndResetPasswordAsync(string token, string newPassword, ResetType resetType);
    

    /// <summary>
    /// 检查密码状态
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <returns>密码状态检查结果</returns>
    Task<ApiResponse<PwdResetDtos>> CheckPasswordStatusAsync(string userId);

    /// <summary>
    /// 重置初始密码
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="currentPassword">当前密码</param>
    /// <param name="newPassword">新密码</param>
    /// <returns>操作结果</returns>
    Task<ApiResponse> ResetInitialPasswordAsync(string userId, string currentPassword, string newPassword);
    #endregion
}

